#!/usr/bin/env python2
# coding=utf-8
import threading
import thread
import time
import sqlite3
import os,sys
from PyQt4 import QtCore
sys.path.append(os.getcwd()+'/WebCrawler/MSpider')
from WebCrawler.MSpider.spider import spiderStart
from data.DataBaseHelper import dataBaseHelper
class startThread(threading.Thread):
    def __init__(self,url,depth=1000,threadnum=10,spidermode=2):
        threading.Thread.__init__(self)
        self.thread_stop=False
        self.test_stop = False
        self.url = url
        self.depth = depth
        self.thnum = threadnum
        self.status = 0
        if spidermode == 0:
            spidermode = 2
        elif spidermode == 2:
            spidermode = 0
        self.spider_mode = spidermode

    def run(self):
        #开始爬虫
        #.......
        args_str = ["-u",self.url,"--depth",self.depth,"-t",self.thnum,"--spider-policy",self.spider_mode]
        self.spider = spiderStart()
        self.spider.main(args_str,)

        
    def stop(self):
        self.thread_stop = True
        self.spider.stop()

 
def main(args_str):
    spider = spiderStart()
    spider.main(args_str)


if __name__ == '__main__':

    #os.chdir("./WebCrawler/MSpoder")
    # print os.getcwd()
    
    sys.exit(int(main(args_str) or 0))